Skip to content

feat: add sequence operator types for event sequencing (A THEN B) #50

Merged
AustinFash merged 5 commits intomainfrom
COMP-2859-define-new-audience-sdk-type-script-types-for-sequencing
Mar 10, 2026
Merged

feat: add sequence operator types for event sequencing (A THEN B) #50
AustinFash merged 5 commits intomainfrom
COMP-2859-define-new-audience-sdk-type-script-types-for-sequencing

Conversation

@AustinFash
Copy link
Contributor

Background

  • Composable Audiences currently support AND/OR-style combination of criteria but cannot express ordering constraints like "A happens, then B happens."
    This blocks common funnel use cases (e.g., conversion funnels, activation steps).
  • This PR defines the TypeScript SDK types required to represent ordered event sequencing (A THEN B) in audience definitions, as specified in the
    Composable Audience Event Sequencing Criteria v1 tech spec.

What Has Changed

  • sdk/typescript-schema/common/operator.ts: Added SequenceOperator type ("then") to represent the new sequence operator alongside existing
    logical/binary/unary operators.
  • sdk/typescript-schema/operand/date-operand.ts: Added AliasPath type to reference a named step's field (e.g., { alias: "event1", path: "timestamp" }). Extended RelativeDate with optional relative_to?: AliasPath to allow Step B's recency window to be anchored relative to Step A's
    timestamp rather than the evaluation timestamp.
  • sdk/typescript-schema/expression/expression.ts: Added SequenceOperand type (a single step with alias, operand: ModelPath, and optional
    condition: Expression) and extended the Expression union type with a then variant ({ operator: SequenceOperator, sequence: SequenceOperand[] }).
  • sdk/typescript-schema/index.ts: Exported ModelPath from the public index (previously unexported, now required as SequenceOperand uses it as
    a public type).

Screenshots/Video

N/A — type-only change.

Checklist

  • I have performed a self-review of my own code.
  • I have made corresponding changes to the documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have tested this locally.

Additional Notes

  • The sequence array on the then expression accepts any number of operands at the type level. V1 restricts sequences to exactly 2 steps (A THEN B),
    but this constraint is enforced in the UI and validation layer — not in the type definition — so that expanding to N-step sequences in future only
    requires a validation change, not a schema change.
  • The relative_to field on RelativeDate is optional and backward-compatible; existing audience definitions without sequencing are unaffected.
  • Downstream changes required in separate PRs: ingest-pipeline SQL generation, mPServer DTO/serialization (SequenceOperator.cs), and UI affordances.

Reference Issue (For employees only. Ignore if you are an outside contributor)

* "condition": { "operator": "equal", "left": { "model": "events", "path": "name" }, "right": "purchase" }
* }
*/
export type SequenceOperand = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave this in a separate file sequence-operand.ts and add it to the operand.ts type

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something in the order of:

export type Operand =
    boolean
    | number
    | string
    | DateOperand
    | ModelPath
    | ModelOperand
    | AudienceOperand
    | SequenceOperand

@mirazik18
Copy link

I believe we still need to update audience-definition-schema.json, audience_model.py, operator.ts, audience-schema.json, and update pyproject.toml.
Look at commits from cameron on how he did it: commit1, commit2

@nathanachang-rokt
Copy link
Contributor

I believe we still need to update audience-definition-schema.json, audience_model.py, operator.ts, audience-schema.json, and update pyproject.toml. Look at commits from cameron on how he did it: commit1, commit2

I think you need to run one of the scripts to write a new schema version from the new .ts files. Start with the README and lmk if you need more help.

"declarationDir": "dist",
"declarationMap": false
"declarationMap": false,
"emitDeclarationOnly": true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a question for Oleg or a code reviewer with more context?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the reason for adding this?

operator: LogicalOperator


class Expression1(BaseModel):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be properly named. I believe Kevin was using this to patch up code gen https://github.com/mParticle/audience-sdk/blob/main/sdk/typescript-schema/scripts/add_titles_to_schema.sh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AustinFash add
$.definitions.Expression.anyOf[3]|SequenceExpression to that file after line 24

* 1. Reference event1's timestamp:
* { alias: "event1", path: "timestamp" }
*/
export type AliasPath = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it only apply to dates? Reads like it shouldn't be in this file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this applies to any generic "alias" but we are using it only for the Event Sequencing use case as of now. We are defining an alias as a CTE to represent a qualified Event (qualified Event meaning the Event data model and any other conditions that specify which Events qualify). Then the path from that alias would be QualifiedEvent.Path (modeled after ModelPath)

Copy link
Contributor

@olegk-rokt olegk-rokt Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets move it to the appropriate file where the model path defined

@AustinFash AustinFash merged commit cebde5a into main Mar 10, 2026
1 check passed
@AustinFash AustinFash deleted the COMP-2859-define-new-audience-sdk-type-script-types-for-sequencing branch March 10, 2026 16:38
mparticle-automation added a commit that referenced this pull request Mar 10, 2026
# [1.5.0](https://github.com/mParticle/audience-sdk/compare/audience-typescript-schema@1.4.2...audience-typescript-schema@1.5.0) (2026-03-10)

### Features

* add sequence operator types for event sequencing (A THEN B)    ([#50](#50)) ([cebde5a](cebde5a))
@mparticle-automation
Copy link
Collaborator

🎉 This PR is included in version 1.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants